#!/usr/bin/env node

const Koa = require('koa');//大写，类

const app = new Koa(),//实例化
      Router = require('koa-router'),
      bodyparser = require('koa-bodyparser'),
      router = new Router,
      log = console.log;


router.get('/api/tasks/',async(ctx,next)=>{
  let {page,limit}= ctx.query;
  log(ctx.header['user-agent']);
    log(`得到代办事件列表,page=${page},limit=${limit}`);
    ctx.body='查询成功';
  })

router.post('/api/tasks/',async(ctx,next)=>{
  let {task} = ctx.request.body;

    log(`提交代办事件,task=${task}`);
    ctx.body='添加成功';
  })

router.put('/api/tasks/:id',async(ctx,next)=>{
  let {id} = ctx.params;
  let {task} = ctx.request.body;
    log(`修改代办事件,id=${id},task={task}`)
    ctx.body='修改成功';
})
  
router.delete('/api/tasks/:id',async(ctx,next)=>{
  let {id} = ctx.params;

    log(`删除代办事件, id=${id}`)
    ctx.body='删除成功';
});

app.use(bodyparser({enableTypes:['json','form','text']}))
app.use(router.routes());


app.listen(8080);




